
layui.use(['layer', 'form', 'admin', 'laydate', 'ax','upload','layedit'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var layer = layui.layer;
    var upload = layui.upload;
    var layedit = layui.layedit;
    // 让当前iframe弹层高度适应
    admin.iframeAuto();

    //获取用户信息
    var ajax = new $ax(Feng.ctxPath + "/drug/getDrugInfo?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    console.log(result.data);
    form.val('drugForm', result.data);

    form.on('select(userid)',function (data){
        var e = data.elem;
        //获取选中的值
        console.log(data.value);
        //获取选中的文本
        var text =e[e.selectedIndex].text;
        $("#name").val(text);
        console.log(text);
    });

    form.on('select(proxyid)',function (data){
        var e = data.elem;
        //获取选中的文本
        var text =e[e.selectedIndex].text;
        $("#proxyname").val(text);
    });

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var val = $("#userid").val();
        var text = $("#userid").text();
        console.log(val + ";" + text);
        var ajax = new $ax(Feng.ctxPath + "/drug/status", function (data) {
            Feng.success("保存成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("修改失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
    });

});